/**
 * 
 */
package com.dsteiner.gwt.cafeteriasophia.client.model;

import java.beans.PropertyChangeListener;
import java.util.List;

import com.dsteiner.gwt.cafeteriasophia.client.domain.ShiftChange;
import com.dsteiner.widgets.client.PropertyChangeCollection;

public class HistoryModel {
	private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(
			this);

	public void addPropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		propertyChangeSupport.registerPropertyChangeListener(propertyName,
				listener);
	}
	
	private List<ShiftChange> shiftChanges;

	public List<ShiftChange> getShiftChanges() {
		return shiftChanges;
	}

	public void setShiftChanges(List<ShiftChange> shiftChanges) {
		List<ShiftChange> oldShiftChanges = this.shiftChanges;
		this.shiftChanges = shiftChanges;
		propertyChangeSupport.firePropertyChange("shiftChanges", oldShiftChanges, shiftChanges);
	}

	public ShiftChange getShiftChange(int i) {
		return shiftChanges != null && !shiftChanges.isEmpty() ? shiftChanges.get(i) : null;
	}

	public ShiftChange getLastShiftChange(ShiftChange shiftChange) {
		int indexOf = shiftChanges.indexOf(shiftChange);
		if(indexOf < shiftChanges.size()-1)
			return shiftChanges.get(indexOf+1);
		else
			return null;
	}
}